package com.sense.kukoo.common.wiget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.sense.kukoo.common.R;

public class NetworkDisconnectView extends FrameLayout {

    private TextView tv_btn_retry;

    public NetworkDisconnectView(@NonNull Context context) {
        super(context);
        init();
    }

    public NetworkDisconnectView(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public NetworkDisconnectView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    public NetworkDisconnectView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        init();
    }

    private void init() {
        LayoutInflater.from(getContext()).inflate(R.layout.common_network_disconnect, this, true);
        //
        tv_btn_retry = findViewById(R.id.tv_btn_retry);
        tv_btn_retry.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mListener != null) {
                    mListener.onRetryClick();
                }
            }
        });
    }

    public interface NetworkDisconnectListener {
        void onRetryClick();
    }

    private NetworkDisconnectListener mListener;

    public void setListener(NetworkDisconnectListener l) {
        mListener = l;
    }
}
